
public class QuickSort
{
    static int list[] = {15,23,2,4,8,9,6,11,12,1,2,3};
    
    /**
     * @param args
     */
    public  static void printList() {
	for(int i = 0; i< list.length ;i++) {
	    System.out.print(list[i]+" ");
	}
    }
    
    public static void quickSort( int m , int n){
	
	
	if (m < n) {
	    int key = list[n];
	    int i = m;
	    int  j = n-1;
	    int temp;
	    while (i <= j) {
		while (i <= n -1 && list[i] <= key ) i++;
		while (j  >= i && list[j] >= key) j--;
		if(i<j) {
		temp = list[i];
		list[i] = list[j];
		list[j] = temp;
		}
	    }
		
	    // Now the crossover is done,
	    temp = list[i];
	    list[i] = key;
	    list[n] = temp;
	    
	    quickSort(m,i-1);
	    quickSort(i+1,n);
	   
	}
    }
    public static void main(String[] args)
    {
       System.out.println("Before sorting the array ");
       printList();
       
	// Now calling the quick sort method here .
        quickSort(0,list.length-1);
        
        System.out.println("\nAfter sorting the array ");
        printList();

    }

}
